package com.udhtu.ii.lab4;

public class Neuron {
    private double[] weigths;
    private double[] in;
    private int Function;

    public Neuron(int count,double[] weigths,double[] in,int Function){
        this.weigths=new double[count];
       this.in=new double[count];
       this.setWeigths(weigths);
        this.setIn(in);
        this.Function=Function;
    }

    private double Sigmoid(double in){
        return 1/(1+Math.exp(-in));
    }

    private double Linear(double in){
        return 1.5*in;
    }
    
    private double Porog(double in){
    	return in<0?0:1;
    }

    public void setWeigths(double[] weigths){

        try{
        for (int i=0;i<weigths.length;i++){
            this.weigths[i]=weigths[i];
        } }
        catch (ArrayIndexOutOfBoundsException ex){
            ex.printStackTrace();
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
    }

    public void setIn(double[] in){

        try{
            for (int i=0;i<in.length;i++){
                this.in[i]=in[i];
            }
        }
        catch (ArrayIndexOutOfBoundsException ex){
            ex.printStackTrace();
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
    }

    public double getIn(){
        double out=0;
        for (int i=0;i<weigths.length;i++){
            out+=in[i]*weigths[i];
        }

        if (Function==1){
        out=Sigmoid(out); }
        else if (Function==2){
            out=Linear(out);
        }
        else if(Function==3){
        	out=Porog(out);
        }
        return out;
    }

    public void printWeigths(){
        for (int i=0;i<weigths.length;i++){
            System.out.println();
        }
    }
}
